"""
重置admin密码的脚本
"""
import asyncio
from sqlalchemy import select
from app.db.session import async_session
from app.models.user import AdminUser
from app.core.security import get_password_hash


async def reset_admin_password():
    """重置admin密码为admin123"""
    async with async_session() as db:
        # 查找admin用户
        result = await db.execute(
            select(AdminUser).where(AdminUser.username == "admin")
        )
        user = result.scalar_one_or_none()
        
        if not user:
            print("❌ 未找到admin用户")
            return
        
        # 重置密码为 admin123
        new_password = "admin123"
        user.password_hash = get_password_hash(new_password)
        
        await db.commit()
        print(f"✅ admin密码已重置为: {new_password}")
        print(f"   用户名: admin")
        print(f"   密码: {new_password}")


if __name__ == "__main__":
    asyncio.run(reset_admin_password())

